<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"/>
    <title>首页 - 图书管理系统</title>
    <link rel="icon" href="../favicon.ico"  th:href="@{../favicon.ico}" type="image/ico">
    <meta name="keywords" content="图书管理系统">
    <meta name="description" content="图书管理系统">
    <meta name="author" content="Superb">
    <link href="../css/bootstrap.min.css"  th:href="@{../css/bootstrap.min.css}" rel="stylesheet">
    <link href="../css/bootstrap-datetimepicker.min.css" th:href="@{../css/bootstrap-datetimepicker.min.css}" rel="stylesheet">
    <link href="../css/materialdesignicons.min.css"  th:href="@{../css/materialdesignicons.min.css}" rel="stylesheet">
    <link href="../css/style.min.css"  th:href="@{../css/style.min.css}" rel="stylesheet">
</head>

<body>
<div class="lyear-layout-web">
    <div class="lyear-layout-container">
        <!--左侧导航-->
        <aside class="lyear-layout-sidebar">

            <!-- logo -->
            <div id="logo" class="sidebar-header">
                <a th:href="@{/index}"><img src="../images/logo-sidebar.png" title="LightYear" alt="LightYear"/></a>
            </div>
            <div class="lyear-layout-sidebar-scroll">

                <div th:replace="~{common/sidebar-main::sidebar-main}"></div>


                <div class="sidebar-footer">
                    <p class="copyright">李杰 &copy; 2022.图书管理系统</p>
                </div>
            </div>

        </aside>
        <!--End 左侧导航-->

        <!--头部信息-->
        <header class="lyear-layout-header">

            <nav class="navbar navbar-default">
                <div class="topbar">

                    <div class="topbar-left">
                        <div class="lyear-aside-toggler">
                            <span class="lyear-toggler-bar"></span>
                            <span class="lyear-toggler-bar"></span>
                            <span class="lyear-toggler-bar"></span>
                        </div>
                        <span class="navbar-page-title"> 图书列表 </span>
                    </div>

                    <ul class="topbar-right">
                        <li class="dropdown dropdown-profile">
                            <a href="javascript:void(0)" data-toggle="dropdown">
                                <img class="img-avatar img-avatar-48 m-r-10" src="../images/users/avatar.jpg" alt=""/>
                                <span th:text="${session.username}"> <span class="caret"></span></span>
                            </a>
                            <ul class="dropdown-menu dropdown-menu-right">
                                <li><a href="lyear_pages_profile.html"><i class="mdi mdi-account"></i> 个人信息</a></li>
                                <li><a href="lyear_pages_edit_pwd.html"><i class="mdi mdi-lock-outline"></i> 修改密码</a>
                                </li>
                                <li><a href="javascript:void(0)"><i class="mdi mdi-delete"></i> 清空缓存</a></li>
                                <li class="divider"></li>
                                <li><a th:href="@{/layout}"><i class="mdi mdi-logout-variant"></i> 退出登录</a></li>
                            </ul>
                        </li>
                        <!--切换主题配色-->
                        <li class="dropdown dropdown-skin">
                            <span data-toggle="dropdown" class="icon-palette"><i class="mdi mdi-palette"></i></span>
                            <ul class="dropdown-menu dropdown-menu-right" data-stopPropagation="true">
                                <li class="drop-title"><p>主题</p></li>
                                <li class="drop-skin-li clearfix">
                  <span class="inverse">
                    <input type="radio" name="site_theme" value="default" id="site_theme_1" checked>
                    <label for="site_theme_1"></label>
                  </span>
                                    <span>
                    <input type="radio" name="site_theme" value="dark" id="site_theme_2">
                    <label for="site_theme_2"></label>
                  </span>
                                    <span>
                    <input type="radio" name="site_theme" value="translucent" id="site_theme_3">
                    <label for="site_theme_3"></label>
                  </span>
                                </li>
                                <li class="drop-title"><p>LOGO</p></li>
                                <li class="drop-skin-li clearfix">
                  <span class="inverse">
                    <input type="radio" name="logo_bg" value="default" id="logo_bg_1" checked>
                    <label for="logo_bg_1"></label>
                  </span>
                                    <span>
                    <input type="radio" name="logo_bg" value="color_2" id="logo_bg_2">
                    <label for="logo_bg_2"></label>
                  </span>
                                    <span>
                    <input type="radio" name="logo_bg" value="color_3" id="logo_bg_3">
                    <label for="logo_bg_3"></label>
                  </span>
                                    <span>
                    <input type="radio" name="logo_bg" value="color_4" id="logo_bg_4">
                    <label for="logo_bg_4"></label>
                  </span>
                                    <span>
                    <input type="radio" name="logo_bg" value="color_5" id="logo_bg_5">
                    <label for="logo_bg_5"></label>
                  </span>
                                    <span>
                    <input type="radio" name="logo_bg" value="color_6" id="logo_bg_6">
                    <label for="logo_bg_6"></label>
                  </span>
                                    <span>
                    <input type="radio" name="logo_bg" value="color_7" id="logo_bg_7">
                    <label for="logo_bg_7"></label>
                  </span>
                                    <span>
                    <input type="radio" name="logo_bg" value="color_8" id="logo_bg_8">
                    <label for="logo_bg_8"></label>
                  </span>
                                </li>
                                <li class="drop-title"><p>头部</p></li>
                                <li class="drop-skin-li clearfix">
                  <span class="inverse">
                    <input type="radio" name="header_bg" value="default" id="header_bg_1" checked>
                    <label for="header_bg_1"></label>
                  </span>
                                    <span>
                    <input type="radio" name="header_bg" value="color_2" id="header_bg_2">
                    <label for="header_bg_2"></label>
                  </span>
                                    <span>
                    <input type="radio" name="header_bg" value="color_3" id="header_bg_3">
                    <label for="header_bg_3"></label>
                  </span>
                                    <span>
                    <input type="radio" name="header_bg" value="color_4" id="header_bg_4">
                    <label for="header_bg_4"></label>
                  </span>
                                    <span>
                    <input type="radio" name="header_bg" value="color_5" id="header_bg_5">
                    <label for="header_bg_5"></label>
                  </span>
                                    <span>
                    <input type="radio" name="header_bg" value="color_6" id="header_bg_6">
                    <label for="header_bg_6"></label>
                  </span>
                                    <span>
                    <input type="radio" name="header_bg" value="color_7" id="header_bg_7">
                    <label for="header_bg_7"></label>
                  </span>
                                    <span>
                    <input type="radio" name="header_bg" value="color_8" id="header_bg_8">
                    <label for="header_bg_8"></label>
                  </span>
                                </li>
                                <li class="drop-title"><p>侧边栏</p></li>
                                <li class="drop-skin-li clearfix">
                  <span class="inverse">
                    <input type="radio" name="sidebar_bg" value="default" id="sidebar_bg_1" checked>
                    <label for="sidebar_bg_1"></label>
                  </span>
                                    <span>
                    <input type="radio" name="sidebar_bg" value="color_2" id="sidebar_bg_2">
                    <label for="sidebar_bg_2"></label>
                  </span>
                                    <span>
                    <input type="radio" name="sidebar_bg" value="color_3" id="sidebar_bg_3">
                    <label for="sidebar_bg_3"></label>
                  </span>
                                    <span>
                    <input type="radio" name="sidebar_bg" value="color_4" id="sidebar_bg_4">
                    <label for="sidebar_bg_4"></label>
                  </span>
                                    <span>
                    <input type="radio" name="sidebar_bg" value="color_5" id="sidebar_bg_5">
                    <label for="sidebar_bg_5"></label>
                  </span>
                                    <span>
                    <input type="radio" name="sidebar_bg" value="color_6" id="sidebar_bg_6">
                    <label for="sidebar_bg_6"></label>
                  </span>
                                    <span>
                    <input type="radio" name="sidebar_bg" value="color_7" id="sidebar_bg_7">
                    <label for="sidebar_bg_7"></label>
                  </span>
                                    <span>
                    <input type="radio" name="sidebar_bg" value="color_8" id="sidebar_bg_8">
                    <label for="sidebar_bg_8"></label>
                  </span>
                                </li>
                            </ul>
                        </li>
                        <!--切换主题配色-->
                    </ul>

                </div>
            </nav>

        </header>
        <!--End 头部信息-->

        <!--页面主要内容-->
        <main class="lyear-layout-content">

            <!--      借阅模态框-->
            <div class="modal fade" id="jyModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                <div class="modal-dialog" role="document">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                    aria-hidden="true">&times;</span>
                            </button>
                            <h4 class="modal-title" id="jyModalLabel"></h4>
                        </div>
                        <div class="modal-body">
                            <form class="form-horizontal" id="formx">
                                <div class="form-group">
                                    <label for="bookNamex" class="col-sm-2 control-label">图书名称</label>
                                    <label class="col-sm-2 control-label" id="bookNamex"></label>
                                </div>

                                <input type="hidden" name="bookId" class="form-control" id="bookIdx">


                                <div class="form-group">
                                    <label for="borrowerName" class="col-sm-2 control-label">借阅人名称</label>
                                    <div class="col-sm-10">
                                        <input type="text" name="borrowerName" class="form-control" id="borrowerName"
                                               placeholder="借阅人名称">
                                        <span class="help-block"></span>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="borrowerPhone" class="col-sm-2 control-label">手机号</label>
                                    <div class="col-sm-10">
                                        <input type="text" name="borrowerPhone" class="form-control" id="borrowerPhone"
                                               placeholder="手机号">
                                        <span class="help-block"></span>
                                    </div>
                                </div>


                                <div class="form-group">
                                    <label for="beginDate" class="col-sm-2 control-label">借阅时间</label>
                                    <div class="col-sm-10">
                                        <input type='text' class="form-control" id='beginDate' name="beginDate"
                                               placeholder="出版时间"/>
                                        <span class="help-block"></span>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="endDate" class="col-sm-2 control-label">计划还书时间</label>
                                    <div class="col-sm-10">
                                        <input type="text" name="endDate" class="form-control" id="endDate"
                                               placeholder="计划还书时间">
                                        <span class="help-block"></span>
                                    </div>
                                </div>


                            </form>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                            <button type="button" id="save_btnx" class="btn btn-primary">保存</button>
                        </div>
                    </div>
                </div>
            </div>
            <!--      添加编辑模态框-->
            <div class="modal fade" id="empModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                <div class="modal-dialog" role="document">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                    aria-hidden="true">&times;</span>
                            </button>
                            <h4 class="modal-title" id="myModalLabel"></h4>
                        </div>
                        <div class="modal-body">
                            <form class="form-horizontal" id="form">
                                <div class="form-group">
                                    <label for="bookName" class="col-sm-2 control-label">图书名称</label>
                                    <div class="col-sm-10">
                                        <input type="text" name="bookName" class="form-control" id="bookName"
                                               placeholder="图书名称">
                                        <span class="help-block"></span>
                                    </div>
                                </div>

                                <input type="hidden" name="bookId" class="form-control" id="bookId">

                                <div class="form-group">
                                    <label for="select" class="col-sm-2 control-label">图书类别</label>
                                    <div class="col-md-4">
                                        <select name="bookType" id="select" class="form-control">
                                            <!--                                填充部门信息-->
                                        </select>
                                        <span class="help-block"></span>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label for="author" class="col-sm-2 control-label">作者</label>
                                    <div class="col-sm-10">
                                        <input type="text" name="author" class="form-control" id="author"
                                               placeholder="作者">
                                        <span class="help-block"></span>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label for="cbs" class="col-sm-2 control-label">出版社</label>
                                    <div class="col-sm-10">
                                        <input type="text" name="cbs" class="form-control" id="cbs" placeholder="出版社">
                                        <span class="help-block"></span>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="col-sm-2 control-label">出版时间</label>
                                    <div class="col-sm-10">
                                        <input type='text' class="form-control" id='cbsj' name="cbsj"
                                               style="width: 200px;" placeholder="出版时间"/>
                                        <span class="help-block"></span>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label for="price" class="col-sm-2 control-label">单价</label>
                                    <div class="col-sm-10">
                                        <input type="text" name="price" class="form-control" id="price"
                                               placeholder="单价">
                                        <span class="help-block"></span>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label for="stock" class="col-sm-2 control-label">库存</label>
                                    <div class="col-sm-10">
                                        <input type="text" name="stock" class="form-control" id="stock"
                                               placeholder="库存">
                                        <span class="help-block"></span>
                                    </div>
                                </div>
                            </form>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                            <button type="button" id="save_btn" class="btn btn-primary">保存</button>
                        </div>
                    </div>
                </div>
            </div>


            <div class="container">
                <div class="row">
                    <!--            添加删除-->
                    <div class="col-md-4 col-md-offset-9">
                        <button id="insert_btn" class="btn btn-success"><span
                                class="glyphicon glyphicon-plus-sign"> 新增</span>
                        </button>
                        <button id="deleteAll_btn" class="btn btn-danger"><span
                                class="glyphicon glyphicon-trash"> 批量删除</span>
                        </button>
                    </div>
                </div>
                <!--        表格-->
                <div class="row">
                    <div class="col-md-12">
                        <table class="table table-hover">
                            <thead>
                            <tr>
                                <th>
                                    <input type="checkbox" id="check"/>
                                </th>
                                <th>图书id</th>
                                <th>条形码</th>
                                <th>书名</th>
                                <th>图书类型</th>
                                <th>作者</th>
                                <th>译者</th>
                                <th>图书编号</th>
                                <th>价格</th>
                                <th>总页数</th>
                                <th>出版日期</th>
                                <th>出版社</th>
                                <th>录入时间</th>
                                <th>总数</th>
                                <th>操作员ID</th>
                                <th>是否下架构</th>
                            </tr>
                            </thead>
                            <tbody>
                            <tr th:each="book:${page}">
                                <td>
                                    <input type="checkbox" class="check-item"/>
                                </td>
                                <td hidden th:text="${bookStat.count}"></td>
                                <td th:text="${book.barcode}"></td>
                                <td th:text="${book.name}"></td>
                                <td th:text="${book.typeId}"></td>
                                <td th:text="${book.author}"></td>
                                <td th:text="${book.translator}"></td>
                                <td th:text="${book.isbn}"></td>
                                <td th:text="${book.price}"></td>
                                <td th:text="${book.page}"></td>
                                <td th:text="${book.publisher}"></td>
                                <td th:text="${book.inTime}"></td>
                                <td th:text="${book.total}"></td>
                                <td th:text="${book.operator}"></td>
                                <td th:text="${book.offShelve}"></td>
<!--                                <td th:text="${book.stock}>0?'上架':'下架'"></td>-->
                                <td>
                                    <button th:id="update_btn" th:emp_id="${book.book_id}"
                                            class="btn btn-primary btn-sm">编辑
                                    </button>
                                    <button th:id="delete_btn" th:emp_id="${book.book_id}"
                                            class="btn btn-danger btn-sm">删除
                                    </button>
                                    <button th:if="${book.stock>0}" th:id="borrow_btn" th:emp_id="${book.book_id}"
                                            class="btn btn-info btn-sm">借阅
                                    </button>
                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
                <!--        尾部-->
                <div class="row">
                </div>
            </div>


        </main>
        <!--End 页面主要内容-->
    </div>
</div>

<script type="text/javascript" th:src="@{../js/jquery.min.js}" src="js/jquery.min.js"></script>
<script type="text/javascript" th:src="@{../js/bootstrap.min.js}" src="js/bootstrap.min.js"></script>
<script type="text/javascript" th:src="@{../js/bootstrap-datetimepicker.min.js}" src="js/bootstrap-datetimepicker.min.js"></script>
<script type="text/javascript" th:src="@{../js/bootstrap-datetimepicker.zh-CN.js}" src="js/bootstrap-datetimepicker.zh-CN.js"></script>
<script type="text/javascript" th:src="@{../js/perfect-scrollbar.min.js}" src="js/perfect-scrollbar.min.js"></script>
<script type="text/javascript" th:src="@{../js/main.min.js}" src="js/main.min.js"></script>

<!--图表插件-->
<script type="text/javascript" src="js/Chart.js"></script>
<script type="text/javascript">

    //为下拉页面大小改变的下拉列表框注册change事件处理器
    $('#pageSizeSelect').change(function (event) {
        //获取当前选择的页面大小值
        var pageSize = $('#pageSizeSelect').val()
        var keyword = $('#keyword').val()
        console.log(pageSize)
        //向后台发送列表查询请求
        window.location = '/customer/customer_list?pageNum=1&pageSize=' + pageSize + '&keyword=' + keyword;

    })

    //为清空关键字按钮注册单击事件，当该按钮被单击后，清空其中关键字
    $('#clearKeyword').click(function (event) {
        var pageSize = $('#pageSizeSelect').val()
        window.location = '/customer/customer_list?pageNum=1&pageSize=' + pageSize;
    })
    //为移除按钮注册单击响应事件
    $('.removeBth').click(function (event) {
        //<a>标签它的默认行为是向服务器发送href定义的url请求
        //这个默认行为是在click事件之后发生的
        //如果用户不删除，即confirm返回false这个被单击事件处理函数返回给浏览器使得这个默认行为不会发生
        return confirm("是否要删除该项?");

    })

    $(document).ready(function () {
        $('#cbsj,#endDate,#beginDate').datetimepicker({
            format: 'yyyy-mm-dd',
            weekStart: 0,
            autoclose: true,
            startView: 2,
            minView: 2,
            forceParse: false,
            todayBtn: true,
            language: 'zh-CN'
        });

    });

    //单个删除
    $(document).on("click", "#delete_btn", function () {
        //弹出删除确认框
        var empName = $(this).parents("tr").find("td:eq(2)").text();
        if (confirm("确认删除【" + empName + "】吗？")) {
            var emp_ids = $(this).attr("emp_id");
            $.ajax({
                url: "/book/info/delete",
                type: "DELETE",
                data: "ids=" + emp_ids,
                success: function (result) {
                    alert(result.msg);
                }
            });
            location.reload();
        }
    });


    //借阅
    $(document).on("click", "#borrow_btn", function () {

        //清空表单样式
        reset_form("#formx");
        //查询emp_id
        var emp_id = $(this).attr("emp_id");
        getEmpx(emp_id);
        $("#jyModalLabel").text("借阅");
        //弹出模态框
        $("#jyModal").modal({
            backdrop: "static"
        });
    });

    //新增
    $("#insert_btn").click(function () {
        //清空表单样式
        reset_form("#form");
        //
        $("#myModalLabel").text("新增");
        //填充部门信息
        getDept("#select");
        //弹出模态框
        $("#empModal").modal({
            backdrop: "static"
        });
    });

    //修改
    $(document).on("click", "#update_btn", function () {

        //查询emp_id
        var emp_id = $(this).attr("emp_id");
        //清空表单样式
        reset_form("#form");
        //填充部门信息+-
        getDept("#select");
        //
        $("#myModalLabel").text("编辑");
        //填充emp
        getEmp(emp_id);
        //将emp_id传递给保存按钮
        // $("#save_btn").attr("emp_id", emp_id);
        //弹出模态框
        $("#empModal").modal({
            backdrop: "static"
        });
    });


    //借阅
    $("#save_btnx").click(function () {
        if (!validate_jy_form()) {
            return false;
        }
        $.ajax({
            url: "/book/borrow/save",
            type: "POST",
            data: $("#formx").serialize(),
            success: function (result) {
                alert(result.msg);
                //关闭
                $("#jyModal").modal('hide');
            }
        });
        location.reload();
    });
    //保存
    $("#save_btn").click(function () {


        if (!validate_add_form()) {
            return false;
        }

        var emp_id = $("#bookId").val();
        //添加
        if (emp_id == null || emp_id == '') {
            $.ajax({
                url: "/book/info/add",
                type: "POST",
                data: $("#form").serialize(),
                success: function (result) {
                    alert(result.msg);
                    //关闭
                    $("#empModal").modal('hide');
                }
            });
        }
        //修改
        else {
            $.ajax({
                url: "/book/info/put",
                type: "PUT",
                data: $("#form").serialize(),
                success: function (result) {
                    alert(result.msg);
                    //关闭
                    $("#empModal").modal('hide');
                }
            });
            //移除emp_id属性
            $(this).removeAttr("emp_id");
        }
        location.reload();
    });


    //批量删除
    $("#deleteAll_btn").click(function () {
        var emp_ids = "";
        var emp_names = "";
        $.each($(".check-item:checked"), function () {
            emp_ids += $(this).parents("tr").find("td:eq(1)").text() + "-";
            emp_names += $(this).parents("tr").find("td:eq(2)").text() + ",";
        })
        if (emp_ids == "" || emp_names == "") {
            alert("未选择");
            return false;
        }
        emp_ids = emp_ids.substring(0, emp_ids.length - 1);
        emp_names = emp_names.substring(0, emp_names.length - 1);
        if (!confirm("确认删除【" + emp_names + "】吗？")) {
            return;
        }
        $.ajax({
            url: "/book/info/delete",
            type: "DELETE",
            data: "ids=" + emp_ids,
            success: function (result) {
                alert(result.msg);
            }
        });
        location.reload();
    });

    //全选全不选
    $("#check").click(function () {
        //自定义属性是attr 原生用prop
        $(".check-item").prop("checked", $(this).prop("checked"));
    });

    $(".check-item").click(function () {
        var flag = $(".check-item:checked").length == $(".check-item").length;
        $("#check").prop("checked", flag);
    });
    $(document).on("click", ".check-item", function () {
        var flag = $(".check-item:checked").length == $(".check-item").length;
        $("#check").prop("checked", flag);
    });


    //添加编辑数据校验
    function validate_add_form() {
        var bookName = $("#bookName").val();
        var author = $("#author").val();
        var cbs = $("#cbs").val();
        var cbsj = $("#cbsj").val();
        var price = $("#price").val();
        var priceTest = /^[0-9]{1,6}$/
        var stock = $("#stock").val();
        var stockTest = /^[0-9]{1,6}$/
        if (bookName == null || bookName == "") {
            show_validate_msg("#bookName", "error", "不能为空");
            return false;
        } else {
            show_validate_msg("#bookName", "success", "输入合法");
        }
        if (author == null || author == "") {
            show_validate_msg("#author", "error", "不能为空");
            return false;
        } else {
            show_validate_msg("#author", "success", "输入合法");
        }
        if (cbs == null || cbs == "") {
            show_validate_msg("#cbs", "error", "不能为空");
            return false;
        } else {
            show_validate_msg("#cbs", "success", "输入合法");
        }
        if (cbsj == null || cbsj == "") {
            show_validate_msg("#cbsj", "error", "不能为空");
            return false;
        } else {
            show_validate_msg("#cbsj", "success", "输入合法");
        }
        if (price == null || price == "") {
            show_validate_msg("#price", "error", "不能为空");
            return false;
        } else if (!priceTest.test(price)) {
            show_validate_msg("#price", "error", "必须为正整数");
            return false;
        } else {
            show_validate_msg("#price", "success", "输入合法");
        }
        if (stock == null || stock == "") {
            show_validate_msg("#stock", "error", "不能为空");
            return false;
        } else if (!stockTest.test(stock)) {
            show_validate_msg("#stock", "error", "必须为正整数");
            return false;
        } else {
            show_validate_msg("#stock", "success", "输入合法");
        }
        return true;
    }


    //借阅数据校验
    function validate_jy_form() {
        var borrowerName = $("#borrowerName").val();
        var borrowerPhone = $("#borrowerPhone").val();
        var phone = /^[0-9]{11}$/;
        var beginDate = $("#beginDate").val();
        var endDate = $("#endDate").val();
        if (borrowerName == null || borrowerName == "") {
            show_validate_msg("#borrowerName", "error", "不能为空");
            return false;
        } else {
            show_validate_msg("#borrowerName", "success", "输入合法");
        }
        if (borrowerPhone == null || borrowerPhone == "") {
            show_validate_msg("#borrowerPhone", "error", "不能为空");
            return false;
        } else if (!phone.test(borrowerPhone)) {
            show_validate_msg("#borrowerPhone", "error", "手机号无效");
            return false;
        } else {
            show_validate_msg("#borrowerPhone", "success", "输入合法");
        }
        if (beginDate == null || beginDate == "") {
            show_validate_msg("#beginDate", "error", "不能为空");
            return false;
        } else {
            show_validate_msg("#beginDate", "success", "输入合法");
        }
        if (endDate == null || endDate == "") {
            show_validate_msg("#endDate", "error", "不能为空");
            return false;
        } else {
            show_validate_msg("#endDate", "success", "输入合法");
        }
        return true;
    }


    //显示校验的验证信息
    function show_validate_msg(ele, status, msg) {
        //清除原先格式
        $(ele).parent().removeClass("has-success has-error");
        $(ele).next("span").text("");
        if ("success" == status) {
            $(ele).parent().addClass("has-success");
            $(ele).next("span").text(msg);
        } else if ("error" == status) {
            $(ele).parent().addClass("has-error");
            $(ele).next("span").text(msg);
        }
    }


    //查询借阅图书名称
    function getEmpx(id) {
        $.ajax({
            url: "/book/info/get",
            type: "GET",
            data: "id=" + id,
            success: function (result) {
                var item = result.data;
                var bookId = item.bookId;
                var bookName = item.bookName;

                $("#bookIdx").val(bookId);
                $("#bookNamex").text(bookName);
            }
        });
    }

    //查询emp并填充修改框
    function getEmp(id) {
        $.ajax({
            url: "/book/info/get",
            type: "GET",
            data: "id=" + id,
            success: function (result) {
                var item = result.data;
                var bookId = item.bookId;
                var bookName = item.bookName;
                var bookType = item.bookType;
                var author = item.author;
                var cbs = item.cbs;
                var cbsj = item.cbsj;
                var price = item.price;
                var stock = item.stock;

                $("#bookId").val(bookId);
                $("#bookName").val(bookName);
                $("#author").val(author);
                $("#cbs").val(cbs);
                $("#cbsj").val(cbsj);
                $("#price").val(price);
                $("#stock").val(stock);
                //为下拉列表填充默认值
                $("#form select").val([bookType]);
            }
        });
    }

    //查询部门信息
    function getDept(ele) {
        //清空
        $(ele).empty();
        $.ajax({
            url: "/book/type/list",
            type: "GET",
            success: function (result) {
                $.each(result.data, function (index, item) {
                    $(ele).append($("<option></option>").append(item.typeName).attr("value", item.id));
                });
            }
        });
    }

    //清空表单样式
    function reset_form(ele) {
        //清空内容
        $(ele)[0].reset();
        //清空表单样式
        $(ele).find("*").removeClass("has-success has-error");
        $(ele).find(".help-block").text("");
    }


</script>
</body>
</html>
